<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"	>

<cc:interface>
	<cc:attribute name="handler"				type="com.hemerasolutions.v2trainer.component.interfaces.table.StatisticTableCompInterface" required="true"/>
	<cc:attribute name="onStatistiUPopUp"		type="java.lang.String" 	default="" 		required="false"/>
	<cc:attribute name="editable"				type="java.lang.Boolean"	default="true"	 required="false"/>	
</cc:interface>

<cc:implementation>
	<span id="#{cc.clientId}" class="ui-statisticTable" >
	
		<h:outputScript library="js" name="statisticTable.js"  />	
	
		<h:panelGrid columns="2" width="100%" style="width:100%;overflow:scroll" columnClasses="top-align,top-align">
			<p:dataTable id="statisticTable" value="#{cc.attrs.handler.trainingStep.trainingStatistics}"  var="trainingStatistic"   styleClass="statisticTable " 
				rendered="#{not empty cc.attrs.handler.trainingStep.trainingStatistics}" >
				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.Exercise}"  />
					</f:facet>	
		            <h:outputText value="#{trainingStatistic.exercise.name}"  rendered="#{trainingStatistic.statisticType lt 2 }" />
		            <h:outputText value="---"  rendered="#{trainingStatistic.statisticType ge 2 }" />

				</p:column>
				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.Execution}"  />
					</f:facet>	
		            <h:outputText value="#{msgs[trainingStatistic.execution.name]}" rendered="#{trainingStatistic.statisticType lt 2 }" />
		            <h:outputText value="---"  rendered="#{trainingStatistic.statisticType ge 2 }" />
				</p:column>
				
				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.Zone}"  />
					</f:facet>	
		            <h:outputText value="#{trainingStatistic.intensityZone.name}"  rendered="#{trainingStatistic.statisticType lt 2 }"/>
		            <h:outputText value="---"  rendered="#{trainingStatistic.statisticType ge 2 }" />
				</p:column>

				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.Volume}"  />
					</f:facet>	
					
					<p:commandLink actionListener="#{cc.attrs.handler.toStatisticPopUp}" oncomplete="#{cc.attrs.onStatistiUPopUp}" 
						update="@(.ui-statisticDetails)" rendered="#{trainingStatistic.statisticType lt 2 }">
						<f:attribute name="trainingStatistic" value="#{trainingStatistic}"/>

						<h:outputText  value="#{trainingStatistic.value}"	  style="vertical-align:top"		rendered="#{!trainingStatistic.volumeFactor.timeBased}" >
							<f:converter converterId="dynamicNumberConverter" />
							<f:attribute name="pattern"	value="#{trainingStatistic.volumeFactor.pattern}" 	 />
						</h:outputText>
						<h:outputText  value="#{trainingStatistic.dateValue}"	  style="vertical-align:top" 	rendered="#{trainingStatistic.volumeFactor.timeBased}" >
							<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
						</h:outputText>

						<h:outputText  value=" #{trainingStatistic.volumeFactor.unit}" />	

						
					</p:commandLink>

		            <h:outputText value="---"  rendered="#{trainingStatistic.statisticType ge 2 }" />
				</p:column>

				
				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.TRest}"  />
					</f:facet>	
					<h:outputText  value="#{trainingStatistic.restTime}"	  style="vertical-align:top">
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
				</p:column>
				<p:column colspan="1"   >
					<f:facet name="header">	
						<h:outputText value="#{msgs.TAction}"  />
					</f:facet>	
					<h:outputText  value="#{trainingStatistic.actionTime}"	  style="vertical-align:top" >
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
				</p:column>
				<p:column colspan="1"  >
					<f:facet name="header">	
						<h:outputText value="#{msgs.TTotal}"  />
		                <h:outputText style="float:right;display:block;height:10px;width:10px;border:0 none;padding:0px" styleClass="droppoint dropright" />
					</f:facet>	
					<h:outputText  value="#{trainingStatistic.totalTime}"	  style="vertical-align:top" >
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
				</p:column>

	 			<p:columns value="#{cc.attrs.handler.trainingStep.statisticUnits}" var="statisticUnit" columnIndexVar="columnIndexVar" style="vertical-align:center;text-align:center;position:relative;max-height:15px !important;padding-top:0px !important;padding-bottom:0px !important;"    >
		            <f:facet name="header">
		                <h:outputText style="float:left;display:block;height:10px;width:10px;border:0 none;padding:0px" styleClass="droppoint dropleft" />                           
		                <h:outputText style="float:right;display:block;height:10px;width:10px;border:0 none;padding:0px" styleClass="droppoint dropright" />
		                <p:outputLabel value="#{msgs[statisticUnit.name]}" title="#{msgs[statisticUnit.description]}"/>
		                 
		            	<h:outputText value="#{statisticUnit.name}" 		style="display:none;width:0px" styleClass="ui-columm-property-unit"   />
		            </f:facet>
					#{trainingStatistic.statistics[columnIndexVar].value}
		        </p:columns>		
				<f:facet name="footer">
					#{msgs.ActionTime} : 
					<h:outputText  value="#{cc.attrs.handler.trainingStep.rootStatistic.actionTime}"	  style="vertical-align:top;margin-right:10px" >
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
					
					#{msgs.Rest} :  
					<h:outputText  value="#{cc.attrs.handler.trainingStep.rootStatistic.restTime}"	  style="vertical-align:top" >
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
					<br/>

					#{msgs.TotalTime} : 
					<h:outputText  value="#{cc.attrs.handler.trainingStep.rootStatistic.totalTime}"	  style="vertical-align:top" >
						<f:convertDateTime pattern="HH:mm:ss" timeZone="GMT0"/>
					</h:outputText>
					<br/>


				</f:facet>
			</p:dataTable>
	
		    <p:tree id="measuresTree" value="#{cc.attrs.handler.rootNode}" var="column" style="float:right;width:200px" rendered="#{cc.attrs.editable and not empty cc.attrs.handler.trainingStep.trainingStatistics}">
		        <p:treeNode >
		            <h:outputText value="#{column}" />
		        </p:treeNode>
		        <p:treeNode type="column" icon="ui-icon-grip-dotted-vertical" >
		            <h:outputText value="#{column.header}" />
		            <h:outputText value="#{column.property}" 					style="display:none;width:0px" styleClass="ui-columm-property-unit"   />
	            	<h:outputText value="#{statisticExecution.execution.name}" 	style="display:none;width:0px" styleClass="ui-columm-property-execution"   />
	            	<h:outputText value="#{statisticTable.level}" 				style="display:none;width:0px" styleClass="ui-columm-property-level"   />
		        </p:treeNode>
		    </p:tree>
		    
		    <p:remoteCommand name="treeToTable_#{cc.clientId.replaceAll('-|:','_')}" rendered="#{cc.attrs.editable}"
		    	actionListener="#{cc.attrs.handler.treeToTable}" update="statisticTable, measuresTree" oncomplete="initStatisticTable();"/>

		    <p:remoteCommand name="tableToTree_#{cc.clientId.replaceAll('-|:','_')}" rendered="#{cc.attrs.editable}"
		    	actionListener="#{cc.attrs.handler.tableToTree}" update="statisticTable, measuresTree" oncomplete="initStatisticTable();"/>

		</h:panelGrid>					
	</span>

</cc:implementation>


</html>